package com.koron.css2.clientCenter.impl;

import com.koron.css2.common.dto.AttachmentDto;
import com.koron.css2.common.service.AbstractExportExcel;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserFieldBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.mapper.UserFieldConfigMapper;
import org.koron.ebs.mybatis.SessionFactory;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class OpenUserExport extends AbstractExportExcel{

//	@Override
//	public AttachmentDto getAttachment(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
//		AttachmentDto attachment = new AttachmentDto();
//		attachment.setBtlTemplate("OpenUserExport.btl");
//		attachment.setData(new ArrayList<String>());
//		attachment.setFilename("开户导入模板");
//		attachment.setFileTemplate("OpenUserExport.xlsx");
//		attachment.setFileType("excel");
//		return attachment;
//	}

	@Override
	public AttachmentDto getAttachment(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {

		UserFieldConfigMapper  userFieldConfigMapper = factory.getMapper(UserFieldConfigMapper.class);
		//有序map，规定导出顺序
		List<Map<String,Object>> result = new ArrayList<Map<String,Object>>();
		List<UserFieldBean> listUserFieldBean = userFieldConfigMapper.findFieldNameByPageNameAndGroupCode("OpenAccount", userInfo.getCurWaterCode());
		result.add(tital(listUserFieldBean));

		AttachmentDto attachment = new AttachmentDto();
		attachment.setBtlTemplate("OpenUserExport.btl");
		attachment.setData(result);
		attachment.setFilename("开户导入模板");
		attachment.setFileTemplate("OpenUserExport.xlsx");
		attachment.setFileType("excel");
		return attachment;
	}


	//组装动态标题
	public Map<String,Object> tital(List<UserFieldBean> detail) {
		Map<String, Object> map = new LinkedHashMap<String, Object>();
		/**
		 * 客户信息
		 */
		map.put("certNo", "客户证件号码");
		map.put("ctmName", "客户名称");
		map.put("clientAddr", "客户结构化地址");
		map.put("clientAddrDetail", "客户单元地址");
		map.put("ctmType", "客户类型");
		map.put("certType", "证件类型");
		map.put("creditLevel", "信用等级");
		map.put("linkTel", "固定电话");
		map.put("mobile", "手机号码");
		map.put("faxNumber", "传真号码");
		/**
		 * 账户信息
		 */
		map.put("payWay", "缴费方式");
		map.put("accountType", "账户类型");
		map.put("deliverWay", "投递方式");
		map.put("deliverAddr", "投递地址");
		map.put("emailAddr", "电子邮件");
		map.put("invoiceTitle", "单位名称");
		map.put("invoiceTax", "纳税人识别号");
		map.put("invoiceAddr", "联系地址");
		map.put("invoiceLink", "座机号码");
		map.put("invoiceBank", "开户银行");
		map.put("invoiceAccount", "银行账户");
		map.put("vatFlag", "增值税标记");
		map.put("preInvoicing", "预开票标记");
		map.put("mergeInvoicing", "合并开票标记");
		/**
		 * 动态获取用户信息（包括用户信息、用户-IC卡信息、用户-水表信息）
		 */
		for (UserFieldBean userFieldBean:detail){
			if (("装表地址").equals(userFieldBean.getFieldName())){
				map.put("clientContractAddr", "装表结构化地址");
				map.put("clientContractAddrDetail", "装表单元地址");
				continue;
			}
			map.put(userFieldBean.getFieldCode(), userFieldBean.getFieldName());
		}

		/**
		 * 用户-价格信息
		 */
		map.put("useWaterType", "用水类型");
		map.put("prefStrategyId", "优惠策略");
		map.put("prefCertNo", "优惠证件号码");
		map.put("prefBeginDate", "优惠策略开始日期");
		map.put("prefEndDate", "优惠策略结束日期");


		return map;
	}
	
}
